<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>显示鼠标单击设置</title>
    <style>
        .mouse{
            position:absolute;
            background-color:red;
            width: 40px;
            height: 40px;
            border-radius: 20px;
        }
    </style>
</head>
<body>
    <div id="mouse" class="mouse"></div> 
</body>
<script>
    //鼠标在页面单击事件时，获取单击时的位置，并显示一个小圆点
    var mouse = document.getElementById("mouse");
    document.onclick = function(event) {
        var event = event || window.event;//获取对象并设置兼容性处理
        //获取当前鼠标所在位置，根据浏览器的版本不同，标准浏览器通过event,pagex
        var pageX = event.pageX || event.clientX + document.documentElement.scrollLeft;//x坐标
        var pageY = event.pageY || event.clientY + document.documentElement.scrollTop;//y坐标

        //计算Div应该显示的位置
        var targetX = pagex - mouse.offsetWidth / 2;
        var targetY = pageY - mouse.offsetHeight / 2;
        //在鼠标单击的位置显示div
        
        mouse.style.display = 'block';
        mouse.style.left = targetX + "px";
        mouse.style.top = targetY + "px";
    }
</script>
</html>